﻿using AutoMapper;
using Pay.Core;
using Pay.Data;
using Pay.DTO;
using Pay.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pay.Service.AutoMapper {
    public class TokenBazaarOrderMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public TokenBazaarOrderMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<TokenBazaarOrder, token_bazaar_order_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.buy_id, src => src.MapFrom(c => c.BuyId))
                .ForMember(dest => dest.buy_merchant_name, src => src.MapFrom(c => c.BuyMerchant.Name))
                .ForMember(dest => dest.buy_merchant_mobile, src => src.MapFrom(c => c.BuyMerchant.Mobile))
                .ForMember(dest => dest.price, src => src.MapFrom(c => c.Price))
                .ForMember(dest => dest.seller_id, src => src.MapFrom(c =>c.SellerId))
                .ForMember(dest => dest.seller_merchant_name, src => src.MapFrom(c => c.SellerMerchant.Name))
                .ForMember(dest => dest.seller_merchant_mobile, src => src.MapFrom(c => c.SellerMerchant.Mobile))
                .ForMember(dest => dest.order_no, src => src.MapFrom(c => c.OrderNo))
                .ForMember(dest => dest.status, src => src.MapFrom(c => c.Status))
                .ForMember(dest => dest.status_desc, src => src.MapFrom(c => c.Status.ToDescription()))
                .ForMember(dest => dest.product_id, src => src.MapFrom(c => c.ProductId))
                .ForMember(dest => dest.product_name, src => src.MapFrom(c => c.TokenBazaarProduct.ProductName))
                .ForMember(dest => dest.prodcut_desc, src => src.MapFrom(c => c.TokenBazaarProduct.ProdcutDesc))
                .ForMember(dest => dest.product_img, src => src.MapFrom(c => c.TokenBazaarProduct.MainImg))
                 .ForMember(dest => dest.product_imgs, src => src.MapFrom(c => c.TokenBazaarProduct.Imgs.ToObject<List<string>>()))
                .ForMember(dest => dest.shipping_type, src => src.MapFrom(c => c.ShippingType))
                .ForMember(dest => dest.ship_name, src => src.MapFrom(c => c.TokenShipping == null ? "" : c.TokenShipping.ShipTo))
                .ForMember(dest => dest.ship_phone, src => src.MapFrom(c => c.TokenShipping == null ? "" : c.TokenShipping.Phone))
                .ForMember(dest => dest.ship_region_name, src => src.MapFrom(c => c.TokenShipping == null ? "" : c.TokenShipping.RegionName))
                .ForMember(dest => dest.ship_address, src => src.MapFrom(c => c.TokenShipping == null ? "" : c.TokenShipping.Address))
                 .ForMember(dest => dest.express_company_name, src => src.MapFrom(c => c.TokenShipping == null ? "" : c.TokenShipping.ExpressCompanyName))
                .ForMember(dest => dest.express_no, src => src.MapFrom(c => c.TokenShipping == null ? "" : c.TokenShipping.ExpressNo))
                 .ForMember(dest => dest.ship_order_number, src => src.MapFrom(c => c.TokenShipping == null ? "" : c.TokenShipping.ShipOrderNumber))
                .ForMember(dest => dest.ship_time, src => src.MapFrom(c => c.TokenShipping == null ? null : c.TokenShipping.ShippingTime.ToDateTime()))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
                  .ForMember(dest => dest.finish_time, src => src.MapFrom(c => c.FinishTime.ToDateTime()))
                .ForMember(dest => dest.update_time, src => src.MapFrom(c => c.UpdateTime.ToDateTime()));



          


        }
    }
}
